<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Project extends Model
{
    use HasFactory;

    protected $fillable = [
        'company_id',
        'name',
        'number',
        'contract_name',
        'contract_number',
        'internal_contract_number',
        'item_name',
        'item_number',
        'director',
        'tax_rate',
        'address',
        'map_address',
        'situation',
        'construction_content',
        'is_rush',
        'is_model_houses',
        'construction_unit',
        'business_type',
        'price',
        'taxation_method',
        'quality_requirement',
        'risk',
        'is_award_presentation',
        'remarks',
        'start_date',
        'end_date',
        'attendance_type',
    ];
    const POSTONLY = [
        'company_id',
        'name',
        'number',
        'contract_name',
        'contract_number',
        'internal_contract_number',
        'item_name',
        'item_number',
        'director',
        'tax_rate',
        'address',
        'map_address',
        'situation',
        'construction_content',
        'is_rush',
        'is_model_houses',
        'construction_unit',
        'business_type',
        'price',
        'taxation_method',
        'quality_requirement',
        'risk',
        'is_award_presentation',
        'remarks',
        'start_date',
        'end_date',
        'attendance_type',
    ];

    protected function serializeDate(\DateTimeInterface $date)
    {
        return $date->format($this->dateFormat ?: 'Y-m-d H:i:s');
    }

    public function teams()
    {
        return $this->hasMany(ProjectTeam::class,'project_id','id')->with('team');
    }

    public function resources()
    {
        return $this->hasMany(ResourceBind::class,'source_id','id')->where('model','Project')->with('resource');
    }

}
